local chengsheng = fk.CreateSkill {
  name = "lingling__chengsheng",
}

Fk:loadTranslationTable{
  ["lingling__chengsheng"] = "乘胜追击",
  [":lingling__chengsheng"] = "当你点数递增使用牌后，若你攻击范围小于3，你可以摸一张牌，本回合攻击范围+1。",

  ["@lingling__chengsheng"] = "乘胜",
  ["#lingling__chengsheng-draw"] = "乘胜追击：你可以摸一张牌，本回合攻击范围+1",
  -- ["#lingling__chengsheng-recast"] = "旋复：你可以重铸一张牌，本回合攻击范围-1",
}

chengsheng:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(chengsheng.name) and data.extra_data then
      if data.extra_data.lingling__chengsheng1 then
        return player:getAttackRange() < 3
      -- elseif data.extra_data.lingling__chengsheng2 then
      --   return player:getAttackRange() > 1 and not player:isNude()
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if data.extra_data.lingling__chengsheng1 then
      return room:askToSkillInvoke(player, {
        skill_name = chengsheng.name,
        prompt = "#lingling__chengsheng-draw",
      })
    -- elseif data.extra_data.lingling__chengsheng2 then
    --   local cards = room:askToCards(player, {
    --     min_num = 1,
    --     max_num = 1,
    --     include_equip = true,
    --     skill_name = chengsheng.name,
    --     prompt = "#lingling__chengsheng-recast",
    --     cancelable = true,
    --   })
      -- if #cards > 0 then
      --   event:setCostData(self, {cards = cards})
      --   return true
      -- end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if data.extra_data.lingling__chengsheng1 then
      room:setPlayerMark(player, "lingling__chengsheng-turn", player:getMark("lingling__chengsheng-turn") + 1)
      player:drawCards(1, chengsheng.name)
    -- else
    --   room:setPlayerMark(player, "lingling__chengsheng-turn", player:getMark("lingling__chengsheng-turn") - 1)
    --   room:recastCard(event:getCostData(self).cards, player, chengsheng.name)
    end
  end,

  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(chengsheng.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    data.extra_data = data.extra_data or {}
    local mark = player:getMark("@lingling__chengsheng")
    if mark ~= 0 and data.card.number ~= mark and data.card.number ~= 0 then
      if data.card.number > mark then
        data.extra_data.lingling__chengsheng1 = true
      -- else
      --   data.extra_data.lingling__chengsheng2 = true
      end
    end
    room:setPlayerMark(player, "@lingling__chengsheng", data.card.number)
  end,
})

chengsheng:addEffect("atkrange", {
  correct_func = function (self, from, to)
    return from:getMark("lingling__chengsheng-turn")
  end,
})

chengsheng:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@lingling__chengsheng", 0)
end)

return chengsheng
